package com.ecarx.vhaltests.hy11.testcases.tcam;

import android.car.VehicleAreaType;
import android.car.VehiclePropertyType;
import android.car.hardware.CarPropertyValue;
import android.car.hardware.property.CarPropertyManager;
import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;

import com.ecarx.vhaltests.IpcpClient;
import com.ecarx.vhaltests.VhalUnitTestBase;
import com.ecarx.xui.adaptapi.automotive.VehicleArea;
import com.ecarx.xui.adaptapi.automotive.VehiclePropertyGroup;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

import android.car.VehicleAreaSeat;

import com.ecarx.vhaltests.VehicleConstants;
import com.ecarx.vhaltests.VhalUnitTestBase2;
import com.ecarx.xui.adaptapi.car.IWrapper;
import com.ecarx.xui.adaptapi.car.vehicle.IVehicle;


/**
 * 数字密钥
 * 3.2.6[SW_FC_050_002] DK BNCM To HMI Messages
 * 创建数字钥匙反馈，需要处理数字反馈信息
 * This packet is DigKeyDataToHMI data
 */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SettingFuncTcamResetActionTest extends VhalUnitTestBase2 {
    private static final String TAG = "SettingFuncTcamResetActionTest";
    private static final IpcpClient ipcpClient = new IpcpClient();

    @BeforeClass
    public static void testInit() {
        setConfig();
    }

    @Override
    protected int getArea() {
        return VehicleArea.GLOBAL;
    }

    @Override
    protected String getValueType() {
        return TYPE_VALUE_BOOLEAN;
    }

    @Override
    protected int getPropertyId() {
        IWrapper.IPropertyId propertyId = getWrapper().getWrappedPropertyId(IWrapper.WrappedIdType.ID_TYPE_FUNCTION, IVehicle.SETTING_FUNC_TCAM_RESET);
        return propertyId.getPropertyId();
    }

    @Test
    public void testSettingFuncTcamResetActionTestNotAvail() {
        setSettingFuncTcamResetActionTestNotAvail();
        Log.e(TAG, "testSettingFuncTcamResetActionTestNotAvail:"); 
    }


    @Test
    public void testSettingFuncTcamResetActionTestAvail_1() {
        setSettingFuncTcamResetActionTestAvail_1();
        Log.e(TAG, "testSettingFuncTcamResetActionTestAvail_1:");
    }

    @Test
    public void testSettingFuncTcamResetActionTestAvail_2() {
        setSettingFuncTcamResetActionTestAvail_2();
        Log.e(TAG, "testSettingFuncTcamResetActionTestAvail_2:");
    }


    public void setSettingFuncTcamResetActionTestAvail_1() {
        setCarConfig(3);
        setCEM(VehicleConstants.CAR_MODE_NOMAL, VehicleConstants.USG_MODE_INACTIVE);
        delay();
    }

    public void setSettingFuncTcamResetActionTestAvail_2() {
        setCarConfig(3);
        setCEM(VehicleConstants.CAR_MODE_DYNO, VehicleConstants.USG_MODE_CONVENIENCE);
        delay();
    }

    public void setSettingFuncTcamResetActionTestNotAvail() {
        setCarConfig(1);
        setCEM(VehicleConstants.CAR_MODE_NOMAL,VehicleConstants.USG_MODE_ABANDON);
        delay();
    }

    private static void setConfig() {
        int ccSvcId = 135;
        int[] ccOperIds = {200};
        int cemSvcId = 37;
        int[] cemOperIds = {999};
        boolean cemSet = ipcpClient.setConfig(cemSvcId,cemOperIds);
        Assert.assertEquals(true, cemSet);
        boolean ccSet = ipcpClient.setConfig(ccSvcId, ccOperIds);
        Assert.assertEquals(true, ccSet);
    }

    public void setCarConfig(int carconfig372) {
        int ccSvcId = 135;
        int ccOperIds = 200;
        int ccOperIdss[] = {ccOperIds};
        int[] configs = {372};
        int[] values = {carconfig372};
        boolean ccResult = ipcpClient.setCarconfigSignal(ccSvcId, ccOperIds, configs, values);
        Assert.assertTrue(ccResult);
        delay();
    }

    public void setCEM(int carMode, int usgMode) {
        int cemSvcId = 37;
        int[] cemOperIds = {999};
        String[] cems = {"vehModMngtGlbSafe1CarModSts1", "vehModMngtGlbSafe1UsgModSts"};
        int[] cemValues = {carMode, usgMode};
        boolean cemResult = ipcpClient.setCEMSignal(cemSvcId, cemOperIds[0], cems, cemValues);
        Assert.assertEquals(true, cemResult);
        delay();
    }
}
